<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;

class getDianZhaData extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('getDianZhaData')
            ->setDescription('下载虫情图片');
    }

    protected function execute(Input $input, Output $output)
    {
        //downloadUrl
        $sql = "select downloadUrl from dz_bug_data where id >= 2607 group by downloadUrl";
        $data = Db::query($sql);
        //var_dump($data);die;
        foreach ($data as $key => $value) {
            // 远程链接
            $remoteUrl = 'http://insect.sennor.net:1881/openFile/'.$value['downloadUrl'];
            $urlArr = explode('/',$remoteUrl);
            $imgName = end($urlArr);
            // 本地保存路径
            $localPath = "D:/phpstudy_pro/WWW/dingzhouapi/app/admin/controller/img/".$imgName;

            // 使用file_get_contents函数获取远程文件的内容
            $content = file_get_contents($remoteUrl);

            // 使用file_put_contents函数将文件内容保存到本地
            file_put_contents($localPath, $content);
        }

        var_dump('ok');die;
    }

}
